<template>
  <div class="knowledge">
    <div class="search-knowledge">
      <el-form
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
        ref="formInline"
      >
        <el-form-item label="名称" prop="name">
          <el-input
            v-model="formInline.name"
            placeholder="请输入知识库名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="type">
          <el-select v-model="formInline.state">
            <el-option label="已发布" value="已发布"></el-option>
            <el-option label="草稿" value="草稿"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="operate">
          <el-button type="primary" @click="onSubmit()">搜索</el-button>
          <el-button @click="resetForm('formInline')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="connect-knowledge">
      <div class="header-connect">
        <el-button type="primary">新建</el-button>
      </div>
      <div class="main-connect">
        <div class="item" v-for="item in list" :key="item.id">
          <dl>
            <dt>
              <img :src="item.url" alt="" />
            </dt>
            <dd>
              <p>{{ item.name }}</p>
              <p>{{ item.connect }}</p>
              <div class="footer">
                <i class="el-icon-edit"></i>
                <i class="el-icon-upload2"></i>
                <i class="el-icon-setting"></i>
                <i class="el-icon-delete"></i>
              </div>
            </dd>
          </dl>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      formInline: {
        name: "",
        type: "",
      },
      list: [],
      pageSize: 10,
      pageIndex: 1,
      total: 0,
    };
  },
  computed: {},
  created() {
    this.getKnowledgeList();
  },
  methods: {
    onSubmit() {
      this.getKnowledgeList();
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 获取知识小测列表
    getKnowledgeList() {
      this.$api
        .getKonwledgeList({
          pageSize: this.pageSize,
          pageIndex: this.pageIndex,
          ...this.formInline,
        })
        .then((res) => {
          console.log(res);
          if (res.success) {
            this.list = res.data.data;
            this.total = res.data.total;
          }
        });
    },
  },
  components: {},
};
</script>
<style lang="scss" scoped>
.knowledge {
  width: 100%;
  height: 100%;
  background-color: #eff2f5;
  display: flex;
  flex-direction: column;
  align-items: center;
  .search-knowledge {
    width: 95%;
    height: 150px;
    background-color: #fff;
    margin-top: 20px;
    .el-form {
      display: flex;
      height: 150px;
      justify-content: space-around;
      align-items: center;
      .operate {
        width: 300px;
        height: 80%;
        display: flex;
        justify-content: end;
        align-items: flex-end;
      }
    }
  }
  .connect-knowledge {
    width: 95%;
    background-color: #fff;
    margin-top: 20px;
    .header-connect {
      height: 60px;
      display: flex;
      align-items: center;
      justify-content: end;
    }
    .main-connect {
      display: flex;
      flex-wrap: wrap;
      .item {
        width: 25%;
        height: 250px;
        margin: 10px 0;
        display: flex;
        justify-content: center;
        dl {
          width: 90%;
          height: 100%;
          border: 1px solid #ccc;
          dt {
            height: 100px;
            img {
              width: 100%;
              height: 100%;
            }
          }
          dd {
            height: 150px;
            display: flex;
            flex-direction: column;
            justify-content: space-around;
            p {
              padding: 0 20px;
            }

            .footer {
              height: 50px;
              display: flex;
              align-items: center;
              justify-content: space-around;
            }
          }
        }
      }
    }
  }
}
</style>